import { requestClient } from '#/api/request';

export namespace CmtCourseInfoApi {
  /** 课程信息 */
  export interface CourseInfo {
    id?: number;
    communityId?: number;
    merchantId?: number;
    categoryId?: number;
    title?: string;
    coverImage?: string;
    teacherPersonId?: number;
    teacherName?: string;
    teacherTitle?: string;
    teacherAvatar?: string;
    difficulty?: number;
    lessonCount?: number;
    duration?: number;
    description?: string;
    content?: string;
    learnCount?: number;
    completeCount?: number;
    rating?: number;
    reviewCount?: number;
    isRecommend?: number;
    isHot?: number;
    sort?: number;
    createTime?: string;
  }

  /** 课程信息分页查询参数 */
  export interface CourseInfoPageReqVO {
    pageNo: number;
    pageSize: number;
    communityId?: number;
    merchantId?: number;
    categoryId?: number;
    title?: string;
    difficulty?: number;
    isRecommend?: number;
    isHot?: number;
    createTime?: string[];
  }
}

/** 查询课程信息分页 */
export function getCourseInfoPage(params: CmtCourseInfoApi.CourseInfoPageReqVO) {
  return requestClient.get<any>('/cmt/course-info/page', { params });
}

/** 查询课程信息详情 */
export function getCourseInfo(id: number) {
  return requestClient.get<CmtCourseInfoApi.CourseInfo>('/cmt/course-info/get', {
    params: { id },
  });
}

/** 新增课程信息 */
export function createCourseInfo(data: CmtCourseInfoApi.CourseInfo) {
  return requestClient.post<number>('/cmt/course-info/create', data);
}

/** 修改课程信息 */
export function updateCourseInfo(data: CmtCourseInfoApi.CourseInfo) {
  return requestClient.put<boolean>('/cmt/course-info/update', data);
}

/** 删除课程信息 */
export function deleteCourseInfo(id: number) {
  return requestClient.delete<boolean>('/cmt/course-info/delete?id=' + id);
}

/** 批量删除课程信息 */
export function deleteCourseInfoList(ids: number[]) {
  return requestClient.delete<boolean>(
    '/cmt/course-info/delete-list?ids=' + ids.join(','),
  );
}

/** 导出课程信息 Excel */
export function exportCourseInfo(params: CmtCourseInfoApi.CourseInfoPageReqVO) {
  return requestClient.get<Blob>('/cmt/course-info/export-excel', {
    params,
    responseType: 'blob',
  });
}

/** 获取课程信息选项列表(用于下拉选择) */
export function getCourseInfoOptions() {
  return requestClient.get<any>('/cmt/course-info/page', {
    params: { pageNo: -1, pageSize: 10 },
  });
}
